
package com.dsiguero.tfg.percentdroid;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends BaseActivity {

    private final static int MAIN_MENU_ITEMS = 6;

    // Array con los id de los elementos del menu
    private static final int[] MENU_ITEMS = { R.id.item1_percentiles, R.id.item2_datosbebe,
            R.id.item3_calendariovacunal, R.id.item4_calendario, R.id.item5_glosario,
            R.id.item6_exportar };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // hacer el replace del layout
        super.replaceContentLayout(R.layout.activity_main, super.CONTENT_LAYOUT_ID);

        // Bind de las activities a los items del menu principal (mas eficiente)
        for (int i = 0; i < MainActivity.MENU_ITEMS.length; i++) {
            this.bindClick(MainActivity.MENU_ITEMS[i], "Item " + (i + 1));
        }
    }

    // TODO modificar eso
    private void bindClick(final int id, final String testItem) {
        MainMenuItemView mmiv = (MainMenuItemView)findViewById(id);
        mmiv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent;

                Class<?> activityToLaunch = null; // Activity a ejecutar en el
                                                  // onClick
                switch (id) {
                    case R.id.item1_percentiles:
                        activityToLaunch = PercentileActivity.class;
                        break;
                    case R.id.item2_datosbebe:
                        activityToLaunch = BabydataActivity.class;
                        break;
                    case R.id.item3_calendariovacunal:
                        activityToLaunch = VaccineActivity.class;
                        break;
                    case R.id.item4_calendario:
                        activityToLaunch = CalendarActivity.class;
                        break;
                    case R.id.item5_glosario:
                        activityToLaunch = GlossaryActivity.class;
                        break;
                    case R.id.item6_exportar:
                        activityToLaunch = ExportActivity.class;
                        break;
                    default:
                        break;
                }

                intent = new Intent(getApplicationContext(), activityToLaunch);
                startActivity(intent);
            }
        });
    }
}
